// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Serverless.Fluent;
using Elastic.Clients.Elasticsearch.Serverless.Requests;
using Elastic.Clients.Elasticsearch.Serverless.Serialization;
using Elastic.Transport;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.Serverless;

public sealed class ReindexRequestParameters : RequestParameters
{
	/// <summary>
	/// <para>If `true`, the request refreshes affected shards to make this operation visible to search.</para>
	/// </summary>
	public bool? Refresh { get => Q<bool?>("refresh"); set => Q("refresh", value); }

	/// <summary>
	/// <para>The throttle for this request in sub-requests per second.<br/>Defaults to no throttle.</para>
	/// </summary>
	public float? RequestsPerSecond { get => Q<float?>("requests_per_second"); set => Q("requests_per_second", value); }

	/// <summary>
	/// <para>Specifies how long a consistent view of the index should be maintained for scrolled search.</para>
	/// </summary>
	public Elastic.Clients.Elasticsearch.Serverless.Duration? Scroll { get => Q<Elastic.Clients.Elasticsearch.Serverless.Duration?>("scroll"); set => Q("scroll", value); }

	/// <summary>
	/// <para>The number of slices this task should be divided into.<br/>Defaults to 1 slice, meaning the task isn’t sliced into subtasks.</para>
	/// </summary>
	public Elastic.Clients.Elasticsearch.Serverless.Slices? Slices { get => Q<Elastic.Clients.Elasticsearch.Serverless.Slices?>("slices"); set => Q("slices", value); }

	/// <summary>
	/// <para>Period each indexing waits for automatic index creation, dynamic mapping updates, and waiting for active shards.</para>
	/// </summary>
	public Elastic.Clients.Elasticsearch.Serverless.Duration? Timeout { get => Q<Elastic.Clients.Elasticsearch.Serverless.Duration?>("timeout"); set => Q("timeout", value); }

	/// <summary>
	/// <para>The number of shard copies that must be active before proceeding with the operation.<br/>Set to `all` or any positive integer up to the total number of shards in the index (`number_of_replicas+1`).</para>
	/// </summary>
	public Elastic.Clients.Elasticsearch.Serverless.WaitForActiveShards? WaitForActiveShards { get => Q<Elastic.Clients.Elasticsearch.Serverless.WaitForActiveShards?>("wait_for_active_shards"); set => Q("wait_for_active_shards", value); }

	/// <summary>
	/// <para>If `true`, the request blocks until the operation is complete.</para>
	/// </summary>
	public bool? WaitForCompletion { get => Q<bool?>("wait_for_completion"); set => Q("wait_for_completion", value); }

	/// <summary>
	/// <para>If `true`, the destination must be an index alias.</para>
	/// </summary>
	public bool? RequireAlias { get => Q<bool?>("require_alias"); set => Q("require_alias", value); }
}

/// <summary>
/// <para>Allows to copy documents from one index to another, optionally filtering the source<br/>documents by a query, changing the destination index settings, or fetching the<br/>documents from a remote cluster.</para>
/// </summary>
public sealed partial class ReindexRequest : PlainRequest<ReindexRequestParameters>
{
	internal override ApiUrls ApiUrls => ApiUrlLookup.NoNamespaceReindex;

	protected override HttpMethod StaticHttpMethod => HttpMethod.POST;

	internal override bool SupportsBody => true;

	internal override string OperationName => "reindex";

	/// <summary>
	/// <para>If `true`, the request refreshes affected shards to make this operation visible to search.</para>
	/// </summary>
	[JsonIgnore]
	public bool? Refresh { get => Q<bool?>("refresh"); set => Q("refresh", value); }

	/// <summary>
	/// <para>The throttle for this request in sub-requests per second.<br/>Defaults to no throttle.</para>
	/// </summary>
	[JsonIgnore]
	public float? RequestsPerSecond { get => Q<float?>("requests_per_second"); set => Q("requests_per_second", value); }

	/// <summary>
	/// <para>Specifies how long a consistent view of the index should be maintained for scrolled search.</para>
	/// </summary>
	[JsonIgnore]
	public Elastic.Clients.Elasticsearch.Serverless.Duration? Scroll { get => Q<Elastic.Clients.Elasticsearch.Serverless.Duration?>("scroll"); set => Q("scroll", value); }

	/// <summary>
	/// <para>The number of slices this task should be divided into.<br/>Defaults to 1 slice, meaning the task isn’t sliced into subtasks.</para>
	/// </summary>
	[JsonIgnore]
	public Elastic.Clients.Elasticsearch.Serverless.Slices? Slices { get => Q<Elastic.Clients.Elasticsearch.Serverless.Slices?>("slices"); set => Q("slices", value); }

	/// <summary>
	/// <para>Period each indexing waits for automatic index creation, dynamic mapping updates, and waiting for active shards.</para>
	/// </summary>
	[JsonIgnore]
	public Elastic.Clients.Elasticsearch.Serverless.Duration? Timeout { get => Q<Elastic.Clients.Elasticsearch.Serverless.Duration?>("timeout"); set => Q("timeout", value); }

	/// <summary>
	/// <para>The number of shard copies that must be active before proceeding with the operation.<br/>Set to `all` or any positive integer up to the total number of shards in the index (`number_of_replicas+1`).</para>
	/// </summary>
	[JsonIgnore]
	public Elastic.Clients.Elasticsearch.Serverless.WaitForActiveShards? WaitForActiveShards { get => Q<Elastic.Clients.Elasticsearch.Serverless.WaitForActiveShards?>("wait_for_active_shards"); set => Q("wait_for_active_shards", value); }

	/// <summary>
	/// <para>If `true`, the request blocks until the operation is complete.</para>
	/// </summary>
	[JsonIgnore]
	public bool? WaitForCompletion { get => Q<bool?>("wait_for_completion"); set => Q("wait_for_completion", value); }

	/// <summary>
	/// <para>If `true`, the destination must be an index alias.</para>
	/// </summary>
	[JsonIgnore]
	public bool? RequireAlias { get => Q<bool?>("require_alias"); set => Q("require_alias", value); }

	/// <summary>
	/// <para>Set to proceed to continue reindexing even if there are conflicts.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("conflicts")]
	public Elastic.Clients.Elasticsearch.Serverless.Conflicts? Conflicts { get; set; }

	/// <summary>
	/// <para>The destination you are copying to.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("dest")]
	public Elastic.Clients.Elasticsearch.Serverless.Core.Reindex.Destination Dest { get; set; }

	/// <summary>
	/// <para>The maximum number of documents to reindex.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("max_docs")]
	public long? MaxDocs { get; set; }

	/// <summary>
	/// <para>The script to run to update the document source or metadata when reindexing.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("script")]
	public Elastic.Clients.Elasticsearch.Serverless.Script? Script { get; set; }
	[JsonInclude, JsonPropertyName("size")]
	public long? Size { get; set; }

	/// <summary>
	/// <para>The source you are copying from.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("source")]
	public Elastic.Clients.Elasticsearch.Serverless.Core.Reindex.Source Source { get; set; }
}

/// <summary>
/// <para>Allows to copy documents from one index to another, optionally filtering the source<br/>documents by a query, changing the destination index settings, or fetching the<br/>documents from a remote cluster.</para>
/// </summary>
public sealed partial class ReindexRequestDescriptor<TDocument> : RequestDescriptor<ReindexRequestDescriptor<TDocument>, ReindexRequestParameters>
{
	internal ReindexRequestDescriptor(Action<ReindexRequestDescriptor<TDocument>> configure) => configure.Invoke(this);

	public ReindexRequestDescriptor()
	{
	}

	internal override ApiUrls ApiUrls => ApiUrlLookup.NoNamespaceReindex;

	protected override HttpMethod StaticHttpMethod => HttpMethod.POST;

	internal override bool SupportsBody => true;

	internal override string OperationName => "reindex";

	public ReindexRequestDescriptor<TDocument> Refresh(bool? refresh = true) => Qs("refresh", refresh);
	public ReindexRequestDescriptor<TDocument> RequestsPerSecond(float? requestsPerSecond) => Qs("requests_per_second", requestsPerSecond);
	public ReindexRequestDescriptor<TDocument> RequireAlias(bool? requireAlias = true) => Qs("require_alias", requireAlias);
	public ReindexRequestDescriptor<TDocument> Scroll(Elastic.Clients.Elasticsearch.Serverless.Duration? scroll) => Qs("scroll", scroll);
	public ReindexRequestDescriptor<TDocument> Slices(Elastic.Clients.Elasticsearch.Serverless.Slices? slices) => Qs("slices", slices);
	public ReindexRequestDescriptor<TDocument> Timeout(Elastic.Clients.Elasticsearch.Serverless.Duration? timeout) => Qs("timeout", timeout);
	public ReindexRequestDescriptor<TDocument> WaitForActiveShards(Elastic.Clients.Elasticsearch.Serverless.WaitForActiveShards? waitForActiveShards) => Qs("wait_for_active_shards", waitForActiveShards);
	public ReindexRequestDescriptor<TDocument> WaitForCompletion(bool? waitForCompletion = true) => Qs("wait_for_completion", waitForCompletion);

	private Elastic.Clients.Elasticsearch.Serverless.Core.Reindex.Source SourceValue { get; set; }
	private Core.Reindex.SourceDescriptor<TDocument> SourceDescriptor { get; set; }
	private Action<Core.Reindex.SourceDescriptor<TDocument>> SourceDescriptorAction { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Conflicts? ConflictsValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Core.Reindex.Destination DestValue { get; set; }
	private Core.Reindex.DestinationDescriptor DestDescriptor { get; set; }
	private Action<Core.Reindex.DestinationDescriptor> DestDescriptorAction { get; set; }
	private long? MaxDocsValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Script? ScriptValue { get; set; }
	private long? SizeValue { get; set; }

	/// <summary>
	/// <para>The source you are copying from.</para>
	/// </summary>
	public ReindexRequestDescriptor<TDocument> Source(Elastic.Clients.Elasticsearch.Serverless.Core.Reindex.Source source)
	{
		SourceDescriptor = null;
		SourceDescriptorAction = null;
		SourceValue = source;
		return Self;
	}

	public ReindexRequestDescriptor<TDocument> Source(Core.Reindex.SourceDescriptor<TDocument> descriptor)
	{
		SourceValue = null;
		SourceDescriptorAction = null;
		SourceDescriptor = descriptor;
		return Self;
	}

	public ReindexRequestDescriptor<TDocument> Source(Action<Core.Reindex.SourceDescriptor<TDocument>> configure)
	{
		SourceValue = null;
		SourceDescriptor = null;
		SourceDescriptorAction = configure;
		return Self;
	}

	/// <summary>
	/// <para>Set to proceed to continue reindexing even if there are conflicts.</para>
	/// </summary>
	public ReindexRequestDescriptor<TDocument> Conflicts(Elastic.Clients.Elasticsearch.Serverless.Conflicts? conflicts)
	{
		ConflictsValue = conflicts;
		return Self;
	}

	/// <summary>
	/// <para>The destination you are copying to.</para>
	/// </summary>
	public ReindexRequestDescriptor<TDocument> Dest(Elastic.Clients.Elasticsearch.Serverless.Core.Reindex.Destination dest)
	{
		DestDescriptor = null;
		DestDescriptorAction = null;
		DestValue = dest;
		return Self;
	}

	public ReindexRequestDescriptor<TDocument> Dest(Core.Reindex.DestinationDescriptor descriptor)
	{
		DestValue = null;
		DestDescriptorAction = null;
		DestDescriptor = descriptor;
		return Self;
	}

	public ReindexRequestDescriptor<TDocument> Dest(Action<Core.Reindex.DestinationDescriptor> configure)
	{
		DestValue = null;
		DestDescriptor = null;
		DestDescriptorAction = configure;
		return Self;
	}

	/// <summary>
	/// <para>The maximum number of documents to reindex.</para>
	/// </summary>
	public ReindexRequestDescriptor<TDocument> MaxDocs(long? maxDocs)
	{
		MaxDocsValue = maxDocs;
		return Self;
	}

	/// <summary>
	/// <para>The script to run to update the document source or metadata when reindexing.</para>
	/// </summary>
	public ReindexRequestDescriptor<TDocument> Script(Elastic.Clients.Elasticsearch.Serverless.Script? script)
	{
		ScriptValue = script;
		return Self;
	}

	public ReindexRequestDescriptor<TDocument> Size(long? size)
	{
		SizeValue = size;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (SourceDescriptor is not null)
		{
			writer.WritePropertyName("source");
			JsonSerializer.Serialize(writer, SourceDescriptor, options);
		}
		else if (SourceDescriptorAction is not null)
		{
			writer.WritePropertyName("source");
			JsonSerializer.Serialize(writer, new Core.Reindex.SourceDescriptor<TDocument>(SourceDescriptorAction), options);
		}
		else
		{
			writer.WritePropertyName("source");
			JsonSerializer.Serialize(writer, SourceValue, options);
		}

		if (ConflictsValue is not null)
		{
			writer.WritePropertyName("conflicts");
			JsonSerializer.Serialize(writer, ConflictsValue, options);
		}

		if (DestDescriptor is not null)
		{
			writer.WritePropertyName("dest");
			JsonSerializer.Serialize(writer, DestDescriptor, options);
		}
		else if (DestDescriptorAction is not null)
		{
			writer.WritePropertyName("dest");
			JsonSerializer.Serialize(writer, new Core.Reindex.DestinationDescriptor(DestDescriptorAction), options);
		}
		else
		{
			writer.WritePropertyName("dest");
			JsonSerializer.Serialize(writer, DestValue, options);
		}

		if (MaxDocsValue.HasValue)
		{
			writer.WritePropertyName("max_docs");
			writer.WriteNumberValue(MaxDocsValue.Value);
		}

		if (ScriptValue is not null)
		{
			writer.WritePropertyName("script");
			JsonSerializer.Serialize(writer, ScriptValue, options);
		}

		if (SizeValue.HasValue)
		{
			writer.WritePropertyName("size");
			writer.WriteNumberValue(SizeValue.Value);
		}

		writer.WriteEndObject();
	}
}

/// <summary>
/// <para>Allows to copy documents from one index to another, optionally filtering the source<br/>documents by a query, changing the destination index settings, or fetching the<br/>documents from a remote cluster.</para>
/// </summary>
public sealed partial class ReindexRequestDescriptor : RequestDescriptor<ReindexRequestDescriptor, ReindexRequestParameters>
{
	internal ReindexRequestDescriptor(Action<ReindexRequestDescriptor> configure) => configure.Invoke(this);

	public ReindexRequestDescriptor()
	{
	}

	internal override ApiUrls ApiUrls => ApiUrlLookup.NoNamespaceReindex;

	protected override HttpMethod StaticHttpMethod => HttpMethod.POST;

	internal override bool SupportsBody => true;

	internal override string OperationName => "reindex";

	public ReindexRequestDescriptor Refresh(bool? refresh = true) => Qs("refresh", refresh);
	public ReindexRequestDescriptor RequestsPerSecond(float? requestsPerSecond) => Qs("requests_per_second", requestsPerSecond);
	public ReindexRequestDescriptor RequireAlias(bool? requireAlias = true) => Qs("require_alias", requireAlias);
	public ReindexRequestDescriptor Scroll(Elastic.Clients.Elasticsearch.Serverless.Duration? scroll) => Qs("scroll", scroll);
	public ReindexRequestDescriptor Slices(Elastic.Clients.Elasticsearch.Serverless.Slices? slices) => Qs("slices", slices);
	public ReindexRequestDescriptor Timeout(Elastic.Clients.Elasticsearch.Serverless.Duration? timeout) => Qs("timeout", timeout);
	public ReindexRequestDescriptor WaitForActiveShards(Elastic.Clients.Elasticsearch.Serverless.WaitForActiveShards? waitForActiveShards) => Qs("wait_for_active_shards", waitForActiveShards);
	public ReindexRequestDescriptor WaitForCompletion(bool? waitForCompletion = true) => Qs("wait_for_completion", waitForCompletion);

	private Elastic.Clients.Elasticsearch.Serverless.Core.Reindex.Source SourceValue { get; set; }
	private Core.Reindex.SourceDescriptor SourceDescriptor { get; set; }
	private Action<Core.Reindex.SourceDescriptor> SourceDescriptorAction { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Conflicts? ConflictsValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Core.Reindex.Destination DestValue { get; set; }
	private Core.Reindex.DestinationDescriptor DestDescriptor { get; set; }
	private Action<Core.Reindex.DestinationDescriptor> DestDescriptorAction { get; set; }
	private long? MaxDocsValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Script? ScriptValue { get; set; }
	private long? SizeValue { get; set; }

	/// <summary>
	/// <para>The source you are copying from.</para>
	/// </summary>
	public ReindexRequestDescriptor Source(Elastic.Clients.Elasticsearch.Serverless.Core.Reindex.Source source)
	{
		SourceDescriptor = null;
		SourceDescriptorAction = null;
		SourceValue = source;
		return Self;
	}

	public ReindexRequestDescriptor Source(Core.Reindex.SourceDescriptor descriptor)
	{
		SourceValue = null;
		SourceDescriptorAction = null;
		SourceDescriptor = descriptor;
		return Self;
	}

	public ReindexRequestDescriptor Source(Action<Core.Reindex.SourceDescriptor> configure)
	{
		SourceValue = null;
		SourceDescriptor = null;
		SourceDescriptorAction = configure;
		return Self;
	}

	/// <summary>
	/// <para>Set to proceed to continue reindexing even if there are conflicts.</para>
	/// </summary>
	public ReindexRequestDescriptor Conflicts(Elastic.Clients.Elasticsearch.Serverless.Conflicts? conflicts)
	{
		ConflictsValue = conflicts;
		return Self;
	}

	/// <summary>
	/// <para>The destination you are copying to.</para>
	/// </summary>
	public ReindexRequestDescriptor Dest(Elastic.Clients.Elasticsearch.Serverless.Core.Reindex.Destination dest)
	{
		DestDescriptor = null;
		DestDescriptorAction = null;
		DestValue = dest;
		return Self;
	}

	public ReindexRequestDescriptor Dest(Core.Reindex.DestinationDescriptor descriptor)
	{
		DestValue = null;
		DestDescriptorAction = null;
		DestDescriptor = descriptor;
		return Self;
	}

	public ReindexRequestDescriptor Dest(Action<Core.Reindex.DestinationDescriptor> configure)
	{
		DestValue = null;
		DestDescriptor = null;
		DestDescriptorAction = configure;
		return Self;
	}

	/// <summary>
	/// <para>The maximum number of documents to reindex.</para>
	/// </summary>
	public ReindexRequestDescriptor MaxDocs(long? maxDocs)
	{
		MaxDocsValue = maxDocs;
		return Self;
	}

	/// <summary>
	/// <para>The script to run to update the document source or metadata when reindexing.</para>
	/// </summary>
	public ReindexRequestDescriptor Script(Elastic.Clients.Elasticsearch.Serverless.Script? script)
	{
		ScriptValue = script;
		return Self;
	}

	public ReindexRequestDescriptor Size(long? size)
	{
		SizeValue = size;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (SourceDescriptor is not null)
		{
			writer.WritePropertyName("source");
			JsonSerializer.Serialize(writer, SourceDescriptor, options);
		}
		else if (SourceDescriptorAction is not null)
		{
			writer.WritePropertyName("source");
			JsonSerializer.Serialize(writer, new Core.Reindex.SourceDescriptor(SourceDescriptorAction), options);
		}
		else
		{
			writer.WritePropertyName("source");
			JsonSerializer.Serialize(writer, SourceValue, options);
		}

		if (ConflictsValue is not null)
		{
			writer.WritePropertyName("conflicts");
			JsonSerializer.Serialize(writer, ConflictsValue, options);
		}

		if (DestDescriptor is not null)
		{
			writer.WritePropertyName("dest");
			JsonSerializer.Serialize(writer, DestDescriptor, options);
		}
		else if (DestDescriptorAction is not null)
		{
			writer.WritePropertyName("dest");
			JsonSerializer.Serialize(writer, new Core.Reindex.DestinationDescriptor(DestDescriptorAction), options);
		}
		else
		{
			writer.WritePropertyName("dest");
			JsonSerializer.Serialize(writer, DestValue, options);
		}

		if (MaxDocsValue.HasValue)
		{
			writer.WritePropertyName("max_docs");
			writer.WriteNumberValue(MaxDocsValue.Value);
		}

		if (ScriptValue is not null)
		{
			writer.WritePropertyName("script");
			JsonSerializer.Serialize(writer, ScriptValue, options);
		}

		if (SizeValue.HasValue)
		{
			writer.WritePropertyName("size");
			writer.WriteNumberValue(SizeValue.Value);
		}

		writer.WriteEndObject();
	}
}